package com.hss01248.facedetect.utils;

import com.bjw.bean.ComBean;
import com.bjw.utils.SerialHelper;
import com.hss01248.facedetect.utils.ToastUtil;

import java.io.IOException;
import java.security.InvalidParameterException;

//灯带串口通讯工具类
public class SHExtends extends SerialHelper {

    public static final String light_red = "A50600A0FF0000A55A";
    public static final String light_green = "A50600A000FF00A55A";
    public static final String light_off = "A50600A0000000A65A";

    @Override
    protected void onDataReceived(ComBean comBean) {


    }

    public SHExtends(String sPort, int iBaudRate) {
        super(sPort, iBaudRate);
    }

    public SHExtends() {
        super();
    }

    public SHExtends(String sPort) {
        super(sPort);
    }

    public SHExtends(String sPort, String sBaudRate) {
        super(sPort, sBaudRate);
    }

    @Override
    public void open() throws SecurityException, IOException, InvalidParameterException {
        super.open();
    }

    @Override
    public void close() {
        super.close();
    }

    @Override
    public void send(byte[] bOutArray) {
        super.send(bOutArray);
    }

    @Override
    public void sendHex(String sHex) {
        super.sendHex(sHex);
    }

    @Override
    public void sendTxt(String sTxt) {
        super.sendTxt(sTxt);
    }

    @Override
    public int getBaudRate() {
        return super.getBaudRate();
    }

    @Override
    public boolean setBaudRate(int iBaud) {
        return super.setBaudRate(iBaud);
    }

    @Override
    public boolean setBaudRate(String sBaud) {
        return super.setBaudRate(sBaud);
    }

    @Override
    public String getPort() {
        return super.getPort();
    }

    @Override
    public boolean setPort(String sPort) {
        return super.setPort(sPort);
    }

    @Override
    public boolean isOpen() {
        return super.isOpen();
    }

    @Override
    public byte[] getbLoopData() {
        return super.getbLoopData();
    }

    @Override
    public void setbLoopData(byte[] bLoopData) {
        super.setbLoopData(bLoopData);
    }

    @Override
    public void setTxtLoopData(String sTxt) {
        super.setTxtLoopData(sTxt);
    }

    @Override
    public void setHexLoopData(String sHex) {
        super.setHexLoopData(sHex);
    }

    @Override
    public int getiDelay() {
        return super.getiDelay();
    }

    @Override
    public void setiDelay(int iDelay) {
        super.setiDelay(iDelay);
    }

    @Override
    public void startSend() {
        super.startSend();
    }

    @Override
    public void stopSend() {
        super.stopSend();
    }


    private void setLightState(String light_state) {
        if (isOpen()) {
            sendHex(light_state);
        } else {
            ToastUtil.showToast("灯带串口未打开");
        }
    }

    public void lightGreen() {
        new Thread(new Runnable() {
            @Override
            public void run() {

                setLightState(light_green);
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                setLightState(light_off);
            }
        }).start();
    }

    public void lightRed() {
        new Thread(new Runnable() {
            @Override
            public void run() {

                setLightState(light_red);
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                setLightState(light_off);
            }
        }).start();
    }

    public void lightOff(){
        setLightState(light_off);
    }

}
